<template>
  <!-- 登录框组件 -->
  <div class="login-box">
    <h1>系统登录页</h1>
    <el-tabs v-model="currentTab" type="border-card" stretch>
      <el-tab-pane name="account">
        <template #label>
          <span>账号登录</span>
        </template>
        <LoginAccount ref="accountRef"></LoginAccount>
      </el-tab-pane>

      <el-tab-pane name="phone">
        <template #label>
          <span>手机登录</span>
        </template>
        <LoginPhone></LoginPhone>
      </el-tab-pane>
    </el-tabs>

    <div class="account-control">
      <el-checkbox v-model="iskeepPassword">记住密码</el-checkbox>
      <el-link type="primary">忘记密码?</el-link>
    </div>
    <el-button class="login-btn" type="primary" @click="handleLoginClick"
      >立即登录</el-button
    >
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import LoginAccount from './LoginAccount.vue'
import LoginPhone from './LoginPhone.vue'
const router = useRouter()
const currentTab = ref('account') // 默认选择手机登录

// 是否记住密码
const iskeepPassword = ref(true)
// 获取组件实例
const accountRef = ref<InstanceType<typeof LoginAccount>>()
// 点击登录
const handleLoginClick = () => {
  if (currentTab.value === 'account') {
    accountRef.value?.loginAction(iskeepPassword.value) //ref要.value
    console.log(`账号登录`)
  } else {
    console.log(`手机登录`)
  }
}
</script>

<style scoped lang="less">
.login-box {
  width: 300px;
  margin-top: 220px;
  h1 {
    text-align: center;
    color: rgb(25, 26, 26);
  }
  .account-control {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    padding: 0 4px;
  }
  .login-btn {
    width: 100%;
  }
}
</style>
